
export const shuffle = (arr) => {
  for (let i = 0; i < arr.length; i++) {
    const randomIndex = Math.round(Math.random() * (arr.length - 1 - i)) + i
    let t = arr[i]
    arr[i] = arr[randomIndex]
    arr[randomIndex] = t
  }
  return arr
}
//
export const copyArr = (arr) => {
  if (!arr.length) {
    return []
  }
  let res = []
  for (let i = 0; i < arr.length; i++) {
    res.push(arr[i])
  }
  return res
}

// 定义一个新的数组
export const createLrc = (lrc) => {
  var medisArray = []
  var medises = lrc.split('\n')

  medises.forEach(element => {
    var t = element.substring(element.indexOf('[') + 1, element.indexOf(']'))
    medisArray.push({
      t: (t.split(':')[0] * 60 + parseFloat(t.split(':')[1])).toFixed(3),
      c: element.substring(element.indexOf(']') + 1, element.length)
    })
  })
  return medises
}
// 从列表中随机取出多个元素

// 截留函数
export function debounce(fun, delay) {
  let timer
  return function(...args) {
    if (timer) {
      clearTimeout(timer)
    }
    timer = setTimeout(() => {
      fun.apply(this, args)
    }, delay)
  }
}